9 int deltaCol
[] = {-2, -1, 1, 2, 2, 1, -1, -2};
10 int deltaFil
[] = {-1, -2, -2, -1, 1, 2, 2, 1};
12 int rdeltaCol
[] = { -1, 0, 1, 1, 1, 0, -1, -1};
13 int rdeltaFil
[] = { -1, -1, -1, 0, 1, 1, 1, 0};
15 int inicialCol
, inicialFil
;
18 unsigned int d
[101][101];
20 int m
, n
; //m filas, n columnas
27 memset(color
, WHITE
, sizeof(color
));
28 for (int i
=0; i
<=100; ++i
) for (int j
=0; j
<=100; ++j
) d
[i
][j
] = UINT_MAX
;
29 color
[inicialFil
][inicialCol
] = GRAY
;
30 d
[inicialFil
][inicialCol
] = 0;
31 queue
< pair
<int,int> > q
;
32 q
.push(make_pair(inicialFil
, inicialCol
));
34 int fil
= q
.front().first
, col
= q
.front().second
;
35 if (g
[fil
][col
] == 'B'){
36 cout
<< "Minimal possible length of a trip is ";
37 cout
<< d
[fil
][col
] << endl
;
40 for (int k
=0; k
<8; ++k
){
42 tempFil
= fil
+ rdeltaFil
[k
];
43 tempCol
= col
+ rdeltaCol
[k
];
44 if ( (tempFil
>= 0) && (tempFil
< m
) && (tempCol
>= 0) && (tempCol
< n
)){
45 char c
= g
[tempFil
][tempCol
];
46 if (c
!= 'Z' && c
!= 'X'){
47 if (color
[tempFil
][tempCol
] == WHITE
){
48 color
[tempFil
][tempCol
] = GRAY
;
49 d
[tempFil
][tempCol
] = d
[fil
][col
] + 1;
50 q
.push(make_pair(tempFil
, tempCol
));
56 color
[fil
][col
] = BLACK
;
58 printf("King Peter, you can't go now!\n");
67 for (int i
=0; i
<m
; ++i
){
68 for (int j
=0; j
<n
; ++j
){
78 for (int i
=0; i
<m
; ++i
){
79 for (int j
=0; j
<n
; ++j
){
81 for (int k
=0; k
<8; ++k
){
83 tempFil
= i
+ deltaFil
[k
];
84 tempCol
= j
+ deltaCol
[k
];
85 if (tempFil
>= 0 && tempFil
<= m
&& tempCol
>=0 && tempCol
< n
){
86 char c
= g
[tempFil
][tempCol
];
87 if (c
!= 'B' && c
!= 'A' && c
!= 'Z') g
[tempFil
][tempCol
] = 'X';
93 //En este momento, g[i][j] contiene una X si es una casilla atacable